using System;
using System.Security.Cryptography;
using System.Text;

namespace Umbraco.Ecommerce.WebShop.UserControls.QuickPay
{
	/// <summary>
	/// Summary description for QuickPayUtil.
	/// </summary>
	
	public class QuickPayUtil
	{		
		public static string md5(string value)
		{
			MD5 md5 = new MD5CryptoServiceProvider();
			byte[] bytes = Encoding.UTF8.GetBytes(value);
			byte[] md5bytes = md5.ComputeHash(bytes);
			
			//string md5String = Encoding.UTF8.GetString(md5bytes);
			string md5String = BytesToHexString(md5bytes);
			return md5String;
		}

		public static String BytesToHexString(byte[] bytes)
		{
			StringBuilder hexString = new StringBuilder(64);

			for (int counter = 0; counter < bytes.Length; counter++)
			{
				hexString.Append(String.Format("{0:X2}", bytes[counter]));
			}
			return hexString.ToString();
		}

		public static string findValue(string content, string key)
		{
			string value = "";
			int index = content.IndexOf(key);
			if (index == -1)
			{
				return value;
			}
			string tmpString = content.Substring(index);
			value = tmpString.Split('"')[1];
			return value;
		}
	}
}
